/**
 * Perform the element default action.
 *
 * @properties={typeid:24,uuid:"64115EC7-996C-449E-AEB1-A03C3B2359B0"}
 */
function confirmar() 
{	
	//borrar los detalles que ye existen para esta boleta
	forms.depositos.boleta_cabecera_to_boleta_detalle.deleteAllRecords();
	
	//recorre los marcados = 1 y genera los detalles todos de nuevo
	var found = databaseManager.getFoundSetCount(foundset)	
	if (found > 0)
	{
		globals.gtotal_cheques = 0 
		for (var i = 1 ; i <= found; i++)
		{		 
			var $rcd = foundset.getRecord(i)
			if ($rcd.marcado_cheque == 1)
			{ //grabar lo que esta marcado en boleta_detalle
				forms.depositos.boleta_cabecera_to_boleta_detalle.newRecord(false)
				forms.depositos.boleta_cabecera_to_boleta_detalle.cheque_id 	= $rcd.cheque_id
				forms.depositos.boleta_cabecera_to_boleta_detalle.importe		= $rcd.importe
				forms.depositos.boleta_cabecera_to_boleta_detalle.movim_cyb_id 	= null
				forms.depositos.boleta_cabecera_to_boleta_detalle.cheque_nro	= $rcd.cheque_nro
		  
				globals.gtotal_cheques += $rcd.importe
			}
		}
	}
	// al final todo ok hacer close del form
	var $win = application.getWindow('chq_en_caja')
	$win.hide()
	$win.destroy()
}

/**
 * Perform the element default action.
 *
 * @properties={typeid:24,uuid:"B73A8284-DEE3-4BF9-9EFB-D96ACBEFB1D2"}
 */
function marcar_todo() 
{
	globals.gtotal_cheques=0;
	var $cant = databaseManager.getFoundSetCount(foundset)
	for (var i = 1 ; i <= $cant ; i++)
	{		 
		var $rcd = foundset.getRecord(i)
		$rcd.marcado_cheque=1
		recalcula_total();
	}
}

/**
 * Perform the element default action.
 *
 * @properties={typeid:24,uuid:"D7992558-1604-4B6F-8DE6-F134AC78C5DA"}
 */
function desmarcar_todo()
{
	globals.gtotal_cheques=0;
	var $cant = databaseManager.getFoundSetCount(foundset)
	for (var i = 1 ; i <= $cant ; i++)
	{		 
		var $rcd = foundset.getRecord(i)
		$rcd.marcado_cheque=0
	}
}

/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"EBFA7552-1EF7-4E4B-9FC0-055A98714D1F"}
 * @AllowToRunInFind
 */
function buscar_chq_en_caja(firstShow, event)
{
	var $estado=foundset.find()
	if ($estado==true)
	{
		globals.gtotal_cheques=0;
		foundset.estado = globals.zconf_chq_en_caja;
		foundset.cuentas_cyb_id = globals.gCuenta_cyb;
		foundset.search();
		var found = databaseManager.getFoundSetCount(foundset)
		globals.gtotal_cheques = 0;
		if (found > 0)
		{
			for (var i = 1 ; i <= found ; i++)
			{
				var $rcd = foundset.getRecord(i)
				if ($rcd.marcado_cheque == 1)
					globals.gtotal_cheques += $rcd.importe
			}
		}
		else
		{
			globals.DIALOGS.showWarningDialog('Aviso','No hay cheques en caja para esa fecha','OK')
		}
	}
}

/**
 * Handle changed data.
 *
 * @param {Object} [oldValue] old value
 * @param {Object} [newValue] new value
 * @param {JSEvent} [event] the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"A2928838-4FAA-43EE-8088-DE6454C627E5"}
 */
function recalcula_total(oldValue, newValue, event) 
{
	globals.gtotal_cheques=0;
	var $cant = databaseManager.getFoundSetCount(foundset)
	for (var i = 1 ; i <= $cant ; i++)
  	{
  		var $rcd = foundset.getRecord(i)
  		if ($rcd.marcado_cheque==1)
			globals.gtotal_cheques += $rcd.importe	 
  	}
  	return true
}
